import requests
import json


def api_query_es():
    url = "http://124.71.67.41:9200/aq_autopublishuploadproduct/_search"
    params = {
        "from": 0,
        "size": 1000,
        "query": {
            "bool": {
                "must": [{
                    "term": {
                        "IsParent": False
                    }
                }, {"term": {"Status": 2}},
                    #{"term": {"SiteCode": "CA"}},

                    {
                    "range": {
                        "AddTime": {
                            "gte": "2024-01-22T00:00:00+08:00",
                            "lte": "2024-01-22T23:59:59+08:00"
                        }
                    }
                }
                ]
            }
        }
    }

    username = "appuser"
    password = "GaaVASPebZ4BH8YU"

    response = requests.post(url, auth=(username, password), json=params)

    data = response.json()
    es_data = []

    order_source_skuid_res = []
    for i in range(10, 12):
        para_data = {}
        data1 = data["hits"]["hits"][i]["_source"]["OrderSourceSKUID"]
        data2 = data["hits"]["hits"][i]["_source"]["SiteCode"]
        para_data["OrderSourceSKUID"] = data1
        para_data["SiteCode"] = data2
        order_source_skuid_res.append(para_data)
    return order_source_skuid_res

# print(api_query_es())
